from django.utils.deprecation import MiddlewareMixin
from django.middleware.security import SecurityMiddleware
from django.http import HttpResponse,JsonResponse
import time
class M1(MiddlewareMixin):
    s_time = time.time()
    def process_request(self,request):
        # 获取接口的url
        print(request.build_absolute_uri())
        print('M1的request')
        # 判断请求反方式
        if request.method == 'GET':
            # 参数的数量
            print(len(request.GET.keys()))
            if len(request.GET.keys())>3:
                return HttpResponse('参数过多')

            print(request.GET)
        else:
            # 参数的数量
            len(request.POST.keys())
            print(request.POST)



    def process_response(self, request, response):
        e_time = time.time()
        print(e_time-self.s_time)
        return response





